package com.watson.test1;

import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;

public class RoundGlyph {

    public static RoundGlyph HOOK = null;

    public void isAlive() {
        System.out.println("yes, i am still alive!");
    }

    @Override
    public void finalize() throws Throwable{
        super.finalize();
        System.out.println("finalize method executed");
        RoundGlyph.HOOK = this;
    }

    public static void main(String[] args) throws InterruptedException {
        HOOK = new RoundGlyph();
        AtomicInteger count = new AtomicInteger(0);
        count.incrementAndGet();

        Semaphore semaphore;

        HOOK = null;
        System.gc();
        Thread.sleep(500);

        if (HOOK == null) {
            System.out.println("no, i am dead!");
        } else {
            HOOK.isAlive();
        }

        HOOK = null;
        System.gc();

        Thread.sleep(500);
        if (HOOK == null) {
            System.out.println("no, i am dead!");
        } else {
            HOOK.isAlive();
        }

    }
}
